package javasy;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class fileEditor extends JFrame {
      JMenuBar jmb=new JMenuBar();
      JButton jb1;
      JButton  jb2;
      JButton  jb3;
      static JTextArea jta=new JTextArea("hello",10,20);
      JScrollPane jsp=new JScrollPane(jta);
      static fileEditor g;
      
      public fileEditor(String str){
    	  super(str);
    	  this.setLocation(200,300);
    	  this.setSize(300,200);
    	  jsp.setBounds(10,30,200,100);
    	  this.setLayout(null);
    	  jb1=new JButton ("打开");
    	  jb2=new JButton ("保存");
    	  jb3=new JButton ("颜色");
    	  jmb.add(jb1);jmb.add(jb2);jmb.add(jb3);
    	  this.setJMenuBar(jmb);
    	  this.add(jsp);
          jta.setEnabled(true);
    	  jb1.addActionListener(new MyActionListener());
    	  jb2.addActionListener(new MyActionListener());
    	  jb3.addActionListener(new MyActionListener());
    	  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	  this.setResizable(false);
    	  this.setVisible(true);
    	  g=this;
      }
      
      public static void setWords(String s_t_r){
    	  jta.append(s_t_r);
      }
      public static String getWords(){
    	  return jta.getText();
      }
      public static void main(String[] args){
    	  fileEditor g=new fileEditor("简单文本编辑器");
      }
      class MyActionListener implements ActionListener{
    	  public void actionPerformed(ActionEvent e){
    		  if(jb1==(JButton)e.getSource()){
    			    g.setVisible(false);
                    try{gui1 gui1_1=new gui1("打开");}
                    catch(Exception a1){
                    	JOptionPane.showMessageDialog(null,"有异常");
                    }
                    g.setVisible(true);
                 }
    		  if(jb2==(JButton)e.getSource()){
    			  g.setVisible(false);
    			  try{gui2 gui_2=new gui2("保存");}
    			  catch(IOException a2){
    				  JOptionPane.showMessageDialog(null,"有异常");
    			  }
    		  }
                if(jb3==(JButton)e.getSource()){
    			  int a=(int)(Math.random()*10);
    			  int b=a%10;
    			  switch(b){
    			  case 0:g.getContentPane().setBackground(Color.black);break;
    			  case 1:g.getContentPane().setBackground(Color.blue);break;
    			  case 2:g.getContentPane().setBackground(Color.cyan);break;
    			  case 3:g.getContentPane().setBackground(Color.DARK_GRAY);break;
    			  case 4:g.getContentPane().setBackground(Color.gray);break;
    			  case 5:g.getContentPane().setBackground(Color.green);break;
    			  case 6:g.getContentPane().setBackground(Color.LIGHT_GRAY);break;
    			  case 7:g.getContentPane().setBackground(Color.magenta);break;
    			  case 8:g.getContentPane().setBackground(Color.orange);break;
    			  case 9:g.getContentPane().setBackground(Color.pink);break;
    			  default:break;
    			  }
    			  
    		  }
    	  }
      }
}